package 空调遥控;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int p = in.nextInt();
        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = in.nextInt();
        }
        int[] res = new int[2];
        int ans = 0;
        Arrays.sort(t);
        for (int i = 0; i < n; i++) {
            int l = 0, r = n - 1;
            while (l < r) {
                int mid = l + r >> 1;
                if (t[mid] >= t[i] - p) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            res[0] = l;
            l = 0;
            r = n - 1;
            while (l < r) {
                int mid = l + r + 1 >> 1;
                if (t[mid] <= t[i] + p) {
                    l = mid;
                } else {
                    r = mid - 1;
                }
            }
            res[1] = l;
            ans = Math.max(ans, res[1] - res[0] + 1);
        }
        System.out.println(ans);
    }
}